package cn.xcstudenth5.zhuocan.scollviewandwebview;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.net.http.SslError;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.SslErrorHandler;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

/**
 * Created by 赵航 on 2020/7/14.
 * WeChat: zhao--hang--
 */
public class ScollViewAdd extends Fragment {

    private View    mSchoolAssignment;
    private WebView mWebView;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mSchoolAssignment = inflater.inflate(R.layout.fragment_scrollview_web, null);
        init(mSchoolAssignment);
        return mSchoolAssignment;
    }

    private String mHtml = "\\\\(\\\\frac{3}{4}\\\\)\",\"\\\\(\\\\frac{2}{3}\\\\)";
    private String PNB = "\n" ;
    private String html = "";
    String three = "<div>在边长为a的正方形中挖去一个边长为b的小正方形（a＞b）（如图甲），把余下的部分拼成一个矩形（如图乙），根据两个图形中阴影部分的面积相等，可以验证（　　）</div><div><img src=\"http://xcimg.zhuocan.com.cn/02/201809/2/20181005094844775728.png\"><br></div>";


    private void init(View schoolAssignment) {

        mWebView = (WebView) schoolAssignment.findViewById(R.id.webview);
        WebSettings settings = mWebView.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setDomStorageEnabled(true);
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        settings.setAllowUniversalAccessFromFileURLs(true);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
        } else {
            settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
        }
        if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.LOLLIPOP){
            settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
        }
        settings.setBlockNetworkImage(false);
//        mWebView.loadData(three, "text/html;charset=utf-8", "utf-8");
        //                mWebView.loadData(string,"text/html","utf-8");
        //        mWebView.loadUrl("https://www.baidu.com");
        //        mWebView.loadUrl("javascript:htmlCall(" + mHtml + ")");
        mWebView.loadDataWithBaseURL(null, three, "text/html","UTF-8", null);

    }
}
